home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / (Notes) / Improve THINK C profiler.doc < prev    next >
Text File  |  1993-12-15  |  3KB  |  49 lines

  1. HISTORY:
  2. October 17, 1990 dgp Wrote it.
  3. June 28, 1991 dgp Changed 60 Hz to 60.15 Hz, as specified by Apple.
  4.  
  5. Here are two simple improvement that you can make to the THINK C profiler. The first will allow it to work even when interrupts are turned off. The second changes the printout to be in conventional units of time (µs or ms), instead of arbitrary ticks.
  6.  
  7. The new VIA_ticks() routine in THINK C 4.0 has the virtue, relative to the preceding version, that it uses interrupts to handle overflow of the VIA clock, so the clock won't overflow even if VIA_ticks() is called very infrequently. However, the new code has the disadvantage that it won't work if interrupts are turned off (by raising the processor priority). Some of my code runs with interrupts off for performance reasons. Obviously I want to be able to time its performance with interrupts off. A trivial change to the new VIA_ticks() routine provides the best of both worlds. Every call to VIA_ticks() resets the timer, postponing the overflow, so VIA_ticks() will work even if interrupts are disabled. Of course it will still overflow if interrupts are disabled AND calls to VIA_ticks() are too infrequent.
  8.  
  9. In the C Libraries folder in your THINK C folder double click the profiler project. Now, in the routine VIA_ticks() in the file VIA_timer.c replace:
  10.  
  11.         elapsed.word.lo = ~timer.word;
  12.  
  13. by this:
  14.  
  15.         VIA[vT1C] = VIA[vT1CH] = ~0;
  16.         elapsed.dword += ~timer.word;
  17.  
  18. Recompile (Command-K) and quit. 
  19.  
  20. You may wish to make another change. This is purely cosmetic, converting the profiler printout to conventional units of time, instead of arbitrary ticks. Open the file profile.c and find the routine DumpProfile(). Just before the routine insert the following definitions:
  21.  
  22.     #ifdef _VIATIMER_
  23.         #define S 1.2766        /* microseconds per VIA tick */
  24.         #define UNIT "(µs)"
  25.     #else
  26.         #define S (1e3/60.15)        /* milliseconds per 60.15 Hz tick */
  27.         #define UNIT "(ms)"
  28.     #endif
  29.  
  30. Then, within the routine, replace the two printf statements by the following modified printf's:
  31.  
  32.         printf("\n%-32s%10s%10s%10s%4s%10s\n"
  33.             ,"","Min"UNIT,"Max"UNIT,"Mean"UNIT,"%","Entries");
  34.  
  35.             printf("%#-32s%10lu\%10lu%10lu%4u%10lu\n",
  36.                         p->fname,
  37.                         p->min == LONG_MAX ? 0L : (unsigned long)(p->min*S),
  38.                         (unsigned long)(p->max*S),
  39.                         p->count ? (unsigned long)(p->total*S / p->count) : 0L,
  40.                         total ? (int) (100. * p->total / total) : 0,
  41.                         p->count);
  42.  
  43. Recompile (Command-K) and quit. 
  44.  
  45. I've suggested to Symantec that they incorporate these changes in the next release of THINK C.
  46.  
  47. Denis
  48.  
  49. p.s. I can't just give you my modified versions of VIA_timer.c and profile.c because they're copyrighted by Symantec.